package com.atguigu.mq.listener;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

//@Component
@Slf4j
public class MyMessageListener6 {
    //定义监听的交换机
    public static final String A = "exchange.test";
    //定义关键字
    public static final String B = "hahaha";
    //注解实现监视消息队列
    @RabbitListener(queues = {"queue.test"})
    public void taet(String dataString, Message message, Channel channel) throws InterruptedException, IOException {
        // 1、获取当前消息的deliveryTag值备用
        long deliveryTag = message.getMessageProperties().getDeliveryTag();

// 2、正常业务操作
        log.info("消费端接收到消息内容：" + dataString);

// System.out.println(10 / 0);
        //TimeUnit.SECONDS.sleep(5);

// 3、给 RabbitMQ 服务器返回 ACK 确认信息
        channel.basicAck(deliveryTag, false);

    }


}
